<?php 
	session_start();
	define('TPL_MODULE','./modules/');
	define('CLASS_DIR','class/');
	define('CLASS_DIR_ADMIN','class/');	
	
	include("../../includes/config.php");
	include("../../includes/constant.php");
	
	include("../../includes/functions.php");
	include("../../includes/va_db.php");
	include("../../class/categories.class.php");
	
	global $db;
	$table_edit = 'image_post_silder';
	
	
	if($_SESSION['type_id'] == '1')
	{
		$article_id = (isset($_SESSION['articles_id'])?$_SESSION['articles_id']:'');
		if($article_id != '')
		{
			$arr['article_id'] = $article_id;
		}
	}
	else
	if($_SESSION['type_id'] == '2')
	{
	
		$product_id = (isset($_SESSION['products_id'])?$_SESSION['products_id']:'');
		if($product_id != '')
		{
			$arr['product_id'] = $product_id;
		}
	}
	else
	if($_SESSION['type_id'] == '3')
	{
	
		$img_id = (isset($_SESSION['img_id'])?$_SESSION['img_id']:'');
		if($img_id != '')
		{
			$arr['img_id'] = $img_id;
		}
	}
?>

<?php

foreach ($_FILES["images"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $name = $_FILES["images"]["name"][$key];
		//echo $_FILES["images"]["name"][$key];
		$path_upload = "../../kam/upload/images/multiFile/";
		$path_upload_real = "kam/upload/images/multiFile/";
		
		$path_full = $path_upload . $_FILES['images']['name'][$key];
		$path_full_real = $path_upload_real . $_FILES['images']['name'][$key];
		
		if(file_exists($path_full))
		{
			$path_full = $path_upload . "2-".$_FILES['images']['name'][$key];
			$path_full_real = $path_upload_real . "2-".$_FILES['images']['name'][$key];
		}
        move_uploaded_file( $_FILES["images"]["tmp_name"][$key], $path_full);
		$arr['url'] = $path_full_real;
		vaInsert($table_edit,$arr);	
    }
}

//echo $table_edit;
//echo $table_edit;	

echo "<h2>Successfully Uploaded Images</h2>";
